package de.hft_stuttgart.dsa.ctt.model;

import java.util.List;

/**
 * This matrix is used within the Pre-Processing steps. Do not use this matrix
 * to assign courses to.
 * 
 * @author Ali Yuruz
 * @author Eduard Tudenhoefner
 */
public class CourseAvailabilityMatrix extends AbstractMatrix {

	public CourseAvailabilityMatrix(List<Room> rooms, List<Period> periods) {
		super(rooms, periods);

		if (null != rooms && null != periods) {
			periodRoomMatrix = new Integer[periods.size()][rooms.size()];
			initializeMatrix();
		} else {
			throw new RuntimeException("Rooms or Periods must not be null");
		}
	}

	private void initializeMatrix() {
		for (int i = 0; i < periodRoomMatrix.length; i++) {
			for (int j = 0; j < periodRoomMatrix[i].length; j++) {
				periodRoomMatrix[i][j] = new Integer(0);
			}
		}
	}

	private boolean isAssignable(int periodIndex, int roomIndex, int calculatedPeriod) {
		if (periodIndex != calculatedPeriod) {
			return true;
		}
		return false;
	}

	public void updateExceptThisOne(int calculatedPeriod) {
		for (int periodIndex = 0; periodIndex < periodRoomMatrix.length; periodIndex++) {
			for (int roomIndex = 0; roomIndex < periodRoomMatrix[periodIndex].length; roomIndex++) {
				// increment old value
				if (isAssignable(periodIndex, roomIndex, calculatedPeriod)) {
					periodRoomMatrix[periodIndex][roomIndex] = new Integer(((Integer) periodRoomMatrix[periodIndex][roomIndex]).intValue() + 1);
				}
			}
		}
	}

}
